﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Diagnostics;

namespace PServiceBus.Core.Runtime {
    public static class Sequence {
        private static readonly object _lockObject = new object();
        private static readonly ulong _processID = (ulong)Process.GetCurrentProcess().Id;
        private static readonly ulong _maxValue = ulong.MaxValue;
        private static readonly Random _random = new Random();
        public static ulong Next {
            get {
                lock (_lockObject) {
                    var tick = (ulong)DateTime.Now.Ticks;
                    return (tick + _processID) % _maxValue;
                    //var tick = (ulong)DateTime.Now.Ticks;
                    //Thread.Sleep(1);
                    //var date = DateTime.Now;
                    //return Convert.ToUInt64(String.Format("{0:yyyyMMddHHmmss}{1}", date, date.Millisecond)) + tick;
                }
            }
        }
    }
}
